package com.example;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class lx1 {
    public static void main(String[] args) throws IOException {
        //1.获取SqlSessionFactoryBuilder对象
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder=new SqlSessionFactoryBuilder();

        //2.通过build()方法，获取SqlSessionFactory对象
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(resourceAsStream);

        //3.通过openSession()，获取SqlSession对象
        SqlSession sqlSession = sqlSessionFactory.openSession();

        int intserCar = sqlSession.insert("intserCar");

        System.out.println("插入了"+intserCar+"记录");

        //4.手动提交
        sqlSession.commit();
        sqlSession.close();
    }
}
